<template>
  <el-dropdown trigger="click" @command="command">
    <slot/>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item v-for="item in densityOptions"
                          :key="item.value"
                          :class="{ 'dropdown-item-selected': size === item.value }"
                          :command="item.value">
          {{ item.label }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script lang="ts" setup>
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ComponentSize } from 'element-plus';

const {t} = useI18n();
const mode = defineModel();
const size = computed({
  get: () => mode.value,
  set: (val) => {
    mode.value = val;
  },
});
const densityOptions = computed(() => [
  {
    value: 'default',
    label: t('table.density.default'),
  },
  {
    value: 'large',
    label: t('table.density.large'),
  },
  {
    value: 'small',
    label: t('table.density.small'),
  },
]);
const command = (value: ComponentSize) => {
  size.value = value;
};
</script>

<style lang="scss" scoped></style>
